package com.zhj.leetcode;

/**
 * 力扣 101 对称二叉树
 */
public class Test101 {
    public static void main(String[] args) {
        TreeNode root = new TreeNode(0);
        root.left = new TreeNode(1);
        root.right = new TreeNode(1);
        root.left.left = new TreeNode(2);
        root.right.right = new TreeNode(3);
        System.out.println(isSymmetric(root));
    }

    public static boolean isSymmetric(TreeNode root) {
        if (root == null) return true;
        return cmp(root.left, root.right);
    }

    private static boolean cmp(TreeNode left, TreeNode right) {
        if (left == null && right == null) return true;
        if (left == null || right == null || left.val != right.val) return false;
        return cmp(left.left, right.right) && cmp(left.right, right.left);
    }
}
